#pragma once
class Window;
#include <map>
#include "messageHandler.h"
using namespace std;

typedef std::map<long, MessageHandler*>  tyMessageGameMap;
typedef tyMessageGameMap::iterator tyMessageIterator;

class Window{
private:
	//Variables
	tyMessageGameMap m_MsgHandlers;
	HWND hwnd;
	HINSTANCE hInstance;
	LPCTSTR lpClassName;
	bool m_UseWaitMessage, m_UsePeekMessage, m_Exit;
	long exitCode;
	ATOM classAtom;
	TCHAR szTitle[100];
	TCHAR szWindowClass[100];
	//Function Headers
	BOOL					InitInstance(	HINSTANCE, 
											int);
	MessageHandler*		Window::GetMessageHandler(long message);
	long					Window::OnClose(Window &wnd, 
											HWND hwnd, 
											long param0, 
											long param1);
	long					Window::OnDestroy(Window &wnd, 
											HWND hwnd, 
											long param0, 
											long param1);

	ATOM					Window::Register(HINSTANCE hInstance);

	void setHWND(HWND hwnd){
		this->hwnd = hwnd;
	}
	bool Window::IsExit(){
		return m_Exit;
	}
public:	
	Window(HINSTANCE hinst);
	HWND					Create(int, int);
	MessageHandler*		RegisterMessageHandler(long message,
                                    MessageHandler *handler);
	static LRESULT CALLBACK MsgRouter(	HWND hwnd,
								UINT message,
								WPARAM wparam,
								LPARAM lparam);
	

	void					ShowWindow(int nCmdShow);
	bool					Window::HandleMessages();
	
	void					Maximize();

	void SetExit(bool b){
		m_Exit = b;
	}
	void SetExitCode(long l){
		exitCode = l;
	}

	long ExitCode(){
		return exitCode;
	}
	void UsePeekMessage(){
		m_UsePeekMessage = !m_UsePeekMessage;
	}
    void UseWaitMessage(){
		m_UseWaitMessage = !m_UseWaitMessage;
	}

};